//
//  ViewController.swift
//  GFQM
//
//  Created by iSolar on 2017/4/20.
//  Copyright © 2017年 iSolar. All rights reserved.
//

import UIKit

class ViewController: UIViewController , UIScrollViewDelegate{

    @IBOutlet weak var headerView: UIView!
    
    @IBOutlet weak var searchBtn: UIButton!
    
    @IBOutlet weak var moreBtn: UIButton!
    
    @IBOutlet weak var bgView: UIImageView!
    
    @IBOutlet weak var messageNum: UILabel!
    
    @IBOutlet weak var footerView: UIView!
    
    @IBOutlet weak var icon: UIImageView!
    
    @IBOutlet weak var list: UIButton!
    
    @IBOutlet weak var nextBtn: UIButton!
    
    @IBOutlet weak var startBtn: UIButton!

    @IBOutlet weak var titleL: MarqueeLabel!
    
    @IBOutlet weak var singerl: MarqueeLabel!
    
    @IBOutlet weak var scrollView: UIScrollView!

    let KScreenWidth: CGFloat = UIScreen.main.bounds.width
    
    let profileV = ProfileView()
    let musicV = MusicStoreView()
    let liveV = LiveView()
    let singV = SingView()

    override func viewDidLoad() {
        super.viewDidLoad()
        setupScrollView()
        searchBtn.addTarget(self, action: #selector(ViewController.searchClick), for: .touchUpInside)
        moreBtn.addTarget(self, action: #selector(ViewController.moreClick), for: .touchUpInside)
        let segment :UISegmentedControl = UISegmentedControl(items: ["我的","乐库","直播","唱歌"])
        segment.selectedSegmentIndex = 0
        segment.frame = CGRect(x: 60, y: 30, width: KScreenWidth-120, height: 40)
        segment.tintColor = UIColor.clear
        
        // 监听事件,当控件值改变的时候做出响应
        segment.addTarget(self, action: #selector(ViewController.action(_:)), for: UIControlEvents.valueChanged)
        //默认状态item字的颜色
        let titleTextAttributes:NSDictionary = [NSForegroundColorAttributeName : UIColor.lightGray, NSFontAttributeName: UIFont.boldSystemFont(ofSize: 16)]
        
        segment.setTitleTextAttributes(titleTextAttributes as? [AnyHashable : Any], for: .normal)
        //选中状态item字的颜色
        segment.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.white, NSFontAttributeName: UIFont.boldSystemFont(ofSize: 16)], for: .selected)
        
        headerView.addSubview(segment)
        
    }
    
}

extension ViewController {
    
    fileprivate func setupScrollView() {
        let width = scrollView.frame.size.width
        let height = scrollView.frame.size.height
        scrollView.showsVerticalScrollIndicator = false
        scrollView.showsHorizontalScrollIndicator = false
        scrollView.isPagingEnabled = true
        scrollView.delegate = self
        scrollView.contentSize = CGSize(width:4*width, height:0)
        
        profileV.x = 0
        profileV.y = 0
        profileV.width = width
        profileV.height = height
        
        
        musicV.x = width
        musicV.y = 0
        musicV.width = width
        musicV.height = height
        
        liveV.x = 2*width
        liveV.y = 0
        liveV.width = width
        liveV.height = height
        
        singV.x = 3*width
        singV.y = 0
        singV.width = width
        singV.height = height
        
        scrollView.addSubview(profileV)
        scrollView.addSubview(musicV)
        scrollView.addSubview(liveV)
        scrollView.addSubview(singV)
        
    }
    
    func  action(_ sender : UISegmentedControl){
        debugPrint(sender.selectedSegmentIndex)
        switch (sender.selectedSegmentIndex){
        case 0:
            
            break
        case 1:
            
            break
        case 2:
            
            break
        case 3:
            
            break
        default:
            break
        }
    }


}

extension ViewController {
    @objc fileprivate func searchClick(){
        
        print("---------------------------")
    }

    @objc fileprivate func moreClick(){
        
        print("---------------------------")
    }

}














